%% Author: jafu
%% Created: 2013-6-16
%% Description: TODO: Add description to clock
-module(clock).

%%
%% Include files
%%

%%
%% Exported Functions
%%
-export([start/2,stop/0]).

%%
%% API Functions
%%

start(Time,Fun) ->
	case whereis(clock) of
		undefined ->
			register(clock,spawn(fun() -> tick(Time,Fun) end) );
		_Any ->
			started
	end.
stop() ->
	case whereis(clock) of
		undefined ->
			not_start;
		_Any ->
			clock ! stop
	end.

%%
%% Local Functions
%%

tick(Time,Fun) ->
	receive
		stop ->
			void
	after Time ->
			Fun(),
			tick(Time,Fun)
	end.
